Тема |
---|
Учебник по добавлению уравнений в верстак FEM |
Уровень |
Время для завершения |
Авторы |
M42kus |
FreeCAD версия |
Примеры файлов |
Смотрите также |
None |
In this tutorial, we are going to add the Flow equation to FreeCAD and implement support for the Elmer solver. Please make sure you have read and understood Extend FEM Module before reading this tutorial.
The task can be split into five parts:
In this step we are going to modify the following file:
The equation type is shared among all equation objects of the different solvers. Each type has a string specifier (e.g. "Heat") and a dedicated command that adds the equation to the selected solver. This allows for a simpler GUI where we have only one button for the heat equation which is used for all supported solver.
First, add the new equation to the equationbase.py
module. Each equation requires two classes. A document proxy and a view proxy. Those two classes will later be used as base classes for the Elmer-specific equation classes. Just copy-paste them from an existing equation type and adjust the icon path inside getIcon(self)
of the view proxy.
class FlowProxy(BaseProxy):
pass
class FlowViewProxy(BaseViewProxy):
def getIcon(self):
return ":/icons/FEM_EquationFlow.svg"
In this step, we are going to implement the document object. We need to add a new flow.py
file at:
and modify the following files:
Let's start with adding the new flow.py
file. This file can be copied from an existing equation.
femsolver/elmer/equations/elasticity.py
module.femsolver/elmer/equations/heat.py
.The flow equation in Elmer is a potentially non-linear equation. This means that we are going to base our work on heat.py
.
After copying heat.py
to flow.py
, adjust flow.py
in these locations:
create
module function,Proxy
class,Type
attribute of the Proxy
class,ViewProxy
classes.def create(doc, name="'''Flow'''"):
return femutils.createObject(
doc, name, Proxy, ViewProxy)
class Proxy(nonlinear.Proxy, equationbase.'''Flow'''Proxy):
Type = "Fem::EquationElmer'''Flow'''"
def __init__(self, obj):
super(Proxy, self).__init__(obj)
obj.Priority = 10
class ViewProxy(nonlinear.ViewProxy, equationbase.'''Flow'''ViewProxy):
pass
Then you need to change the properties added via the obj.addProperty(..)
function to those needed by the equation.
At the moment of writing this tutorial Elmer flow equation doesn't have any special properties. See the Elmer elasticity equation for an example with properties.
Finally one has to register a makeEquationFlow definition in src/Mod/Fem/ObjectsFem.py
by duplicating an available entry.
FreeCAD uses make to build the program. So we need to register the new module file (flow.py
) in src/Mod/Fem/CMakeLists.txt
the way described in Extend FEM Module. The suitable lists can be easily found by searching for existing equation module files of Elmer.
In this step we are going to modify the following file:
Right now we made FreeCAD aware that there is a new type of equation and even added a command that adds this equation to the selected solver object. We also implemented a concrete equation object for Elmer. What's left to do now is to make the connection between Elmer and the flow equation. This must be done directly in the Elmer solver object.
Register the module in which we just implemented our new equation object (flow.py
) with the equation specifier from step 1 ("Flow") in the _EQUATIONS
list in elmer/solver.py
.
from .equations import electrostatic
+from .equations import flow
...
_EQUATIONS = {
"Heat": heat,
"Elasticity": elasticity,
+ "Flow": flow,
}
In this step we are going to modify the following file:
This file contains the Writer
class which exports the analysis into Elmer SIF format.
For every supported equation, there are two main methods handling the export of the respective equation. Just copy all of them from an existing equation and adjust them to your needs.
_getFlowSolver
_handleFlow
You need to register the _handleFlow
method inside the Writer
class:
class Writer(object):
...
def write(self):
...
self._handleFlow()
...
_handleFlow
can control a series of other detailed methods. Our flow equation uses the following detailed methods:
_handleFlowConstants
_handleFlowMaterial
_handleFlowInitialVelocity
_handleFlowBndConditions
_handleFlowEquation
We now finished the function part of the new equation. Next, we'll connect the new equation through the GUI.
We have just created a new equation class. To access it from the FEM GUI, we need to create a button and link it to the new equation class. Here is a tutorial: Add Button to FEM Toolbar Tutorial.